package main

import (
	"fmt"
	"strconv"
)

func main() {
	var str string = "284"
	var i int
	var i64 int64

	// int and string
	fmt.Println("str = ", str)
	//string to int
	i, _ = strconv.Atoi(str)
	fmt.Println("str to int = ", i)
	//sting to int64
	i64, _ = strconv.ParseInt(str, 0, 0)
	fmt.Println("str to int64 = ", i64)
	//int to string
	str = strconv.Itoa(i)
	fmt.Println("int to string = ", str)
	//int64 to string
	str = strconv.FormatInt(i64, 10)
	fmt.Println("int64 to string = ", str)

	var f float64 = 3.8415926
	//float to string
	//-1 代表输出的精度小数点后的位数，如果是<0的值，则返回最少的位数来表示该数，如果是大于0的则返回对应位数的值
	str = strconv.FormatFloat(f, 'f', -1, 64) // 64 or 32
	fmt.Println("float64 to string ", str)
	//string to float
	str = "3.8415926"
	f, _ = strconv.ParseFloat(str, 64) // 64 or 32
	fmt.Println("string to float ", f)

	// string to []byte
	str = "hello world"
	var bb []byte = []byte(str)
	fmt.Println("string to []byte", str, bb)
	fmt.Println("[]byte to string ", str, string(bb))
}
